package com.xuanyuan.service;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;

import com.xuanyuan.dao.SendMessageDao;
import com.xuanyuan.model.Departments;
import com.xuanyuan.util.Model2VoUtil;
import com.xuanyuan.util.PageInfo;
import com.xuanyuan.vo.DepartmentsVo;

@Component("sendMessageService")
public class SendMessageService {
    SendMessageDao sendMessageDao;

    @Resource
	public void setSendMessageDao(SendMessageDao sendMessageDao) {
		this.sendMessageDao = sendMessageDao;
	}
	
	public List<DepartmentsVo> getUsersVo(PageInfo pageInfo) {
		List<Departments> us = sendMessageDao.getUsers(pageInfo);
		List<DepartmentsVo> uVo = new ArrayList<DepartmentsVo>();
		for(Departments s : us){
			DepartmentsVo u = new DepartmentsVo();
		 	u = Model2VoUtil.getDepartmentsVo(s);
			uVo.add(u);
		}
		return uVo;
	}
    
	public List<DepartmentsVo> getUsersVoByDepartment(String department, PageInfo pageInfo) {
		 List<DepartmentsVo> uVo = new ArrayList<DepartmentsVo>();
		 List<Departments> u = sendMessageDao.getUsersByDepartment(department, pageInfo);
		 for(Departments s : u){
			 DepartmentsVo us = new DepartmentsVo();
			 us = Model2VoUtil.getDepartmentsVo(s);
			 uVo.add(us);
		 }
		 return uVo;
	}
	
	public List<DepartmentsVo> getDapartmentsById(Integer departmentsId,
			PageInfo pageInfo) {
		List<DepartmentsVo> dVoList = new ArrayList<DepartmentsVo>();
	    List<Departments> d = sendMessageDao.getDapartmentsById(departmentsId, pageInfo);
	    for(Departments ds : d){
	    	DepartmentsVo dVo = new DepartmentsVo();
	    	dVo = Model2VoUtil.getDepartmentsVo(ds);
	    	dVoList.add(dVo);
	    }
		return dVoList;
	}
}
